from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(450, 550)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        MainWindow.setCentralWidget(self.centralwidget)
        self.listview = QtWidgets.QListView(self.centralwidget)
        self.listview.setGeometry(QtCore.QRect(10,10,400,300))
        self.listview.setObjectName("listview")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setObjectName("pushButton")
        self.pushButton.setGeometry(QtCore.QRect(300,380,100,20))

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
         _translate = QtCore.QCoreApplication.translate
         MainWindow.setWindowTitle(_translate("MainWindow", "App"))
         self.pushButton.setText(_translate("MainWindow", "Retrieve data"))


class Ui_SecondWindow(object):
    def setupUi(self,SecondWindow):
        SecondWindow.setObjectName("SecondWindow")
        SecondWindow.resize(600, 400)
        self.centralwidget = QtWidgets.QWidget(SecondWindow)
        self.centralwidget.setObjectName("centralwidget")
        SecondWindow.setCentralWidget(self.centralwidget)

        self.tableView = QtWidgets.QTableView(self.centralwidget)
        self.tableView.setGeometry(QtCore.QRect(10,10,580,370))

        self.retranslateUi(SecondWindow)
        QtCore.QMetaObject.connectSlotsByName(SecondWindow)

    def retranslateUi(self,SecondWindow):
        _translate = QtCore.QCoreApplication.translate
        SecondWindow.setWindowTitle(_translate("SecondWindow", "Table"))

class SecondWindow(QtWidgets.QMainWindow, Ui_SecondWindow):
    def __init__(self, parent=None):
        super(SecondWindow, self).__init__(parent)
        self.setupUi(self)

class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.pushButton.clicked.connect(self.btn_clk)
        path = r'./'
        self.fileModel = QtWidgets.QFileSystemModel(self.centralwidget)
        self.fileModel.setRootPath(path)
        self.fileModel.setFilter(QtCore.QDir.NoDotAndDotDot | QtCore.QDir.Files)
        self.listview.setModel(self.fileModel)
        self.listview.setRootIndex(self.fileModel.index(path))
        self.listview.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
        self.sw = SecondWindow()

    @QtCore.pyqtSlot()
    def btn_clk(self):
        for ix in self.listview.selectedIndexes():
            filename = self.fileModel.filePath(ix)
            df = pd.read_csv(filename)
            self.model = PandasModel(df)
            self.sw.tableView.setModel(self.model)
            self.sw.show()
            return

if __name__ == "__main__":
    import sys
    from PyQt5.QtCore import Qt
    from PyQt5.QtWidgets import QApplication

    # 高分辨率屏幕适应
    if hasattr(Qt, 'AA_EnableHighDpiScaling'):
        QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
    if hasattr(Qt, 'AA_UseHighDpiPixmaps'):
        QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)

    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())